package com.shixi.shixitraining.shixitraining.util;

import android.text.TextUtils;

/**
 * 用户信息管理
 *
 */

public class UserManager {

    private static UserManager userManager;

    public static synchronized UserManager getInstance() {
        if (userManager == null) {
            userManager = new UserManager();
        }
        return userManager;
    }


    /**
     * 获取用户是否登录
     *
     * @return
     */
    public boolean isUserLogged() {
        String userId = (String) SharePreferenceUtil.get(SharePreferenceUtil.SPFILENAME
                .FILE_NAME, "userid", "");
        return !TextUtils.isEmpty(userId) && !"0".equals(userId);
    }

    /**
     * 获取用户userId
     *
     * @return
     */
    public String getUserId() {
        return (String) SharePreferenceUtil.get(SharePreferenceUtil.SPFILENAME.FILE_NAME,
                "userid", "");
    }

    /**
     * 保存用户userId
     *
     * @param userId
     */
    public void saveUserId(String userId) {
        SharePreferenceUtil.put(SharePreferenceUtil.SPFILENAME.FILE_NAME, "userid", userId);
    }

    //获取用户头像
    public String getUserIcon() {
        return (String) SharePreferenceUtil.get(SharePreferenceUtil.SPFILENAME.FILE_NAME,
                "userPhoto", "");
    }

    //保存用户头像
    public void setUserIcon(String photo) {
        SharePreferenceUtil.put(SharePreferenceUtil.SPFILENAME.FILE_NAME, "userPhoto", photo);
    }

    /**
     * 获取用户昵称
     *
     * @return
     */
    public String getUserName() {
        return (String) SharePreferenceUtil.get(SharePreferenceUtil.SPFILENAME.FILE_NAME,
                "userName", "");
    }

    /**
     * 保存用户昵称
     *
     * @param name
     */
    public void saveUserName(String name) {
        SharePreferenceUtil.put(SharePreferenceUtil.SPFILENAME.FILE_NAME, "userName", name);
    }

    //保存token
    public void saveToken(String token) {
        SharePreferenceUtil.put(SharePreferenceUtil.SPFILENAME.FILE_NAME, "userToken", token);
    }

    public String getToken() {
        return (String) SharePreferenceUtil.get(SharePreferenceUtil.SPFILENAME.FILE_NAME,
                "userToken", "");
    }

    /**
     * 获取用户密码
     * @return
     */
    public  String getUserPassWord(){
        return (String) SharePreferenceUtil.get(SharePreferenceUtil.SPFILENAME.FILE_NAME,
                "userPsw", "");
    }
    /**
     * 保存密码
     * @param passWord
     */
    public void savePassWord(String passWord){
        SharePreferenceUtil.put(SharePreferenceUtil.SPFILENAME.FILE_NAME, "userPsw", passWord);
    }

    public boolean isUserRegister(){
        String signusersIdcard = (String) SharePreferenceUtil.get(SharePreferenceUtil.SPFILENAME
                .FILE_NAME, "signusersidcard", "");
        return !TextUtils.isEmpty(signusersIdcard) && !"0".equals(signusersIdcard);
    }


}
